﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace employee.Controls
{
    public partial class emPrivate : common.controls.baseUserControl
    {
        public emPrivate()
        {
            InitializeComponent();
        }

        BindingSource lastDataSrc = null;
        public virtual void Init(BindingSource dataSrc)
        {
            nationalityCb.LoadData();
            ethnicCb.LoadData();
            religionCb.LoadData();
            maritalStatCb.LoadData();
            bloodTypeCb.LoadData();
            eduLeveCb.LoadData();
            comUnionStatCb.LoadData();
            comPartyStatCb.LoadData();
            expertiseCb.LoadData();

            SetDataSource(dataSrc);
            this.lastDataSrc = dataSrc;
        }
        public new void Refresh()
        {
            if (this.lastDataSrc != null) SetDataSource(this.lastDataSrc);
        }

        protected void SetDataSource(BindingSource dataSrc)
        {
            common.BindingLibs.BindObject(this.dobEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.dobColumn.ColumnName);
            common.BindingLibs.BindObject(this.pobEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.pobColumn.ColumnName);
            common.BindingLibs.BindObject(this.placeOfOriginEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.placeOfOriginColumn.ColumnName);
            common.BindingLibs.BindObject(this.nationalityCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.nationality1Column.ColumnName,"myValue");
            common.BindingLibs.BindObject(this.ethnicCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.ethnicColumn.ColumnName);

            common.BindingLibs.BindObject(this.religionCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.religionColumn.ColumnName, "myValue");
            common.BindingLibs.BindObject(this.maritalStatCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.maritalStatusColumn.ColumnName);

            common.BindingLibs.BindObject(this.eduLeveCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.eduLevelColumn.ColumnName, "myValue");
            common.BindingLibs.BindObject(this.eduAreaEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.eduAreaColumn.ColumnName);
            common.BindingLibs.BindObject(this.bloodTypeCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.bloodGroupColumn.ColumnName);

            common.BindingLibs.BindObject(this.comPartyDateEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.comPartyJoinDateColumn.ColumnName);
            common.BindingLibs.BindObject(this.comUnionDateEd, dataSrc, DataAccess.DataCache.myBaseDS.employee.comUnionJoinDateColumn.ColumnName);

            common.BindingLibs.BindObject(this.comPartyStatCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.comPartyStatusColumn.ColumnName);
            common.BindingLibs.BindObject(this.comUnionStatCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.comUnionStatusColumn.ColumnName);

            common.BindingLibs.BindObject(this.expertiseCb, dataSrc, DataAccess.DataCache.myBaseDS.employee.expertiseColumn.ColumnName, "myItemString");

            this.expertiseCb.maxLen = DataAccess.DataCache.myBaseDS.employee.expertiseColumn.MaxLength;
            this.dobEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.dobColumn.MaxLength;
            this.placeOfOriginEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.placeOfOriginColumn.MaxLength;
            this.eduAreaEd.MaxLength = DataAccess.DataCache.myBaseDS.employee.eduAreaColumn.MaxLength;

            this.expertiseCb.minSelectedItems = 0;
        }

        public virtual bool CheckData()
        {
            bool retVal = true;
            ClearNotifyError();
            if (dobEd.myValue == common.Consts.constNullDate)
            {
                NotifyError(dobLbl);
                retVal = false;
            }
            if (pobEd.Text.Trim() == "")
            {
                NotifyError(pobLbl);
                retVal = false;
            }

            if (!expertiseCb.DataValid(false))
            {
                NotifyError(expertiseLbl);
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            state = !state;
            dobEd.Enabled = state;
            pobEd.Enabled = state;
            placeOfOriginEd.Enabled = state;

            nationalityCb.Enabled = state;
            ethnicCb.Enabled = state;
            religionCb.Enabled = state;
            maritalStatCb.Enabled = state;

            eduLeveCb.Enabled = state;
            eduAreaEd.Enabled = state;

            bloodTypeCb.Enabled = state;

            comPartyGb.Enabled = state;
            comUnionGb.Enabled = state;
            expertiseCb.Enabled = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            dobEd.Focus();
        }
    }
}
